package com.efeichong.common.config;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.filter.AbstractMatcherFilter;
import ch.qos.logback.core.spi.FilterReply;

/**
 * @author lxk
 * @date 2021/12/08
 * @description 打印debug和info级别的日志
 */
public class InfoLoggerFilter extends AbstractMatcherFilter<ILoggingEvent> {
    Level level;

    @Override
    public FilterReply decide(ILoggingEvent event) {
        if (event.getLevel() == Level.DEBUG || event.getLevel() == Level.INFO) {
            return FilterReply.ACCEPT;
        }
        return FilterReply.DENY;
    }

    public void setLevel(Level level) {
        this.level = level;
    }

    @Override
    public void start() {
        if (this.level != null) {
            super.start();
        }

    }
}